package com.ruoyi.system.controller;

import com.dime.basic.api.model.Combo;
import com.dime.basic.api.model.ComboBase;
import com.fasterxml.jackson.databind.ser.Serializers;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.model.UserShop;
import com.ruoyi.system.domain.BaseShop;
import com.ruoyi.system.domain.dto.ShopDto;
import com.ruoyi.system.domain.vo.ShopVo;
import com.ruoyi.system.service.IBaseShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2022-09-29
 */
@RestController
@RequestMapping("/shop")
public class BaseShopController extends BaseController
{
    @Autowired
    private IBaseShopService baseShopService;

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:shop:list")
    @GetMapping("/list")
    public TableDataInfo list(BaseShop baseShop)
    {
        startPage();
        List<BaseShop> list = baseShopService.selectBaseShopList(baseShop);
        return getDataTable(list);
    }
    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:shop:list")
    @GetMapping("/shoplist")
    public TableDataInfo shoplist(ShopDto baseShop)
    {
        startPage();
        List<ShopVo> list = baseShopService.selectShopList(baseShop);
        return getDataTable(list);
    }
    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:shop:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseShop baseShop)
    {
        List<BaseShop> list = baseShopService.selectBaseShopList(baseShop);
        ExcelUtil<BaseShop> util = new ExcelUtil<BaseShop>(BaseShop.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @RequiresPermissions("system:shop:query")
    @GetMapping(value = "/{shopId}")
    public AjaxResult getInfo(@PathVariable("shopId") Long shopId)
    {
        return AjaxResult.success(baseShopService.selectBaseShopByShopId(shopId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @RequiresPermissions("system:shop:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopDto baseShop)
    {
        return toAjax(baseShopService.insertBaseShop(baseShop));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("system:shop:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseShop baseShop)
    {
        return toAjax(baseShopService.updateBaseShop(baseShop));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:shop:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shopIds}")
    public AjaxResult remove(@PathVariable Long[] shopIds)
    {
        return toAjax(baseShopService.deleteBaseShopByShopIds(shopIds));
    }

    /**
     * 内部接口，获取门店信息
     * @param shopCode
     * @return
     */
    @InnerAuth
    @GetMapping("/info/{shopCode}")
    public R<UserShop> getBaseShopByShopCode(@PathVariable("shopCode") String shopCode)
    {
        UserShop shop = baseShopService.getUserShopsByShopCode(shopCode);
        if(StringUtils.isNotNull(shop))
            return R.ok(shop);
        return R.fail(StringUtils.format("没有找到编号： {} 的商铺！",shopCode));
    }
}
